<?php

function getExperience() {
    $tabExperience = array();
    if (isset($_SESSION[EXPERIENCE]) && !empty($_SESSION[EXPERIENCE]) && !isset($_GET['refresh']))
        $tabExperience = $_SESSION[EXPERIENCE];
    else {
        $myExperience = Experience::getAll();

        if (isset($myExperience) && count($myExperience) > 0) {
            foreach ($myExperience as $experience) {

                $expDateIn = $experience->dateIn();
                $expDateOut = $experience->dateOut();

                $getDateIn = getdate($expDateIn->getTimestamp());
                $expDates = date_format($expDateIn, "Y F");
                if($expDateOut != null){
                    $getDateOut = getdate($expDateOut->getTimestamp());
                    if ($getDateIn["year"] == $getDateOut["year"]) {
                        if ($getDateIn["month"] != $getDateOut["month"])
                            $expDates .= '-' . date_format($expDateOut, "F");
                    }
                    else
                        $expDates .= '-' . date_format($expDateOut, "Y F");
                }else
                    $expDates .= '-Present';
                array_push($tabExperience, array('experience' => $experience, 'expDates' => $expDates));
            }
        }
        $_SESSION[EXPERIENCE] = $tabExperience;
    }
    return $tabExperience;
}

?>